package com.zhs.smartmall.member.service.impl;


import com.zhs.smartmall.member.model.UmsIntegrationChangeHistory;
import com.zhs.smartmall.member.dao.UmsIntegrationChangeHistoryDao;
import com.zhs.smartmall.member.service.IUmsIntegrationChangeHistoryService;
import com.zhs.smartmall.member.dto.UmsIntegrationChangeHistoryDto;


import com.zhs.smartmallcommon.exception.ServiceException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.smartmallcommon.Enum.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;


/**
 *
 * @author 
 * @since 2023-11-15
 */
@Service
@Slf4j
public class UmsIntegrationChangeHistoryServiceImpl extends ServiceImpl< UmsIntegrationChangeHistoryDao, UmsIntegrationChangeHistory> implements IUmsIntegrationChangeHistoryService {

    @Resource
    private UmsIntegrationChangeHistoryDao umsIntegrationChangeHistoryDao;

    @Override
    @Transactional
    public R addOrUpdate(UmsIntegrationChangeHistoryDto umsIntegrationChangeHistoryDto) {
        if (BeanUtil.isEmpty(umsIntegrationChangeHistoryDto)) throw new ServiceException("数据不能为空");
        UmsIntegrationChangeHistory umsIntegrationChangeHistory = new UmsIntegrationChangeHistory();
        BeanUtil.copyProperties(umsIntegrationChangeHistoryDto,umsIntegrationChangeHistory);
        if (umsIntegrationChangeHistoryDto.getId() == null){
            umsIntegrationChangeHistoryDao.insert(umsIntegrationChangeHistory);
            return R.ok("数据插入成功");
        }else {
            umsIntegrationChangeHistoryDao.updateById(umsIntegrationChangeHistory);
            return R.ok("数据更新成功");
        }
    }
}